 <html>
 <body>
 <?php 
 $con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("loc_fil", $con);
   session_start();
	$a=$_SESSION['val'];
	$b=$_SESSION['val1'];
	$c=$_SESSION['val2'];
	$d=$_SESSION['val3'];
   if (isset($_GET['page'])) 
{ 
$page = $_GET['page'];
$page=mysql_real_escape_string($page); 
}
else $page=1;

//Here we count the number of results 
//Edit $data to be your query 
$result=mysql_query("SELECT * FROM theatres where Loc_latitude BETWEEN $a and $b and Loc_longitude BETWEEN $c and $d") or die(mysql_error()); 
$rows = mysql_num_rows($result);

//This is the number of results displayed per page 
$per_page = 5;

//This tells us the page number of our last page 
$total_pages = ceil($rows/$per_page);
echo"you are on page $page of $total_pages<br/>";
if($page!=1)
{ echo "<a href='theatres_search.php?page=1'><<First</a>"." ";
  $previous=$page-1;
  echo "<a href='theatres_search.php?page=$previous'><<Previous</a>";
}
if(($page!=1)&&($page!=total_pages))
  echo "|";
  
  if($page!= $total_pages)
  { $next=$page+1;
    echo"<a href='theatres_search.php?page=$next'>Next>></a>"." ";
    echo"<a href='theatres_search.php?page=$total_pages'>Last>></a>";
  }
  echo "<hr><br/>";
  
  $x=($page-1)*$per_page;
  $result=mysql_query("SELECT * FROM theatres where Loc_latitude BETWEEN $a and $b and Loc_longitude BETWEEN $c and $d Limit $x,$per_page");
  ?> 
<table border="1">
<tr>
<th>Th_id</th>
<th>Th_Name</th>
</tr>
<?php
while($row = mysql_fetch_array($result))
 {?>
<tr>
<td><?php echo $row['Th_id']?> </td>
<td><?php echo $row['Th_Name']?> </td>
</tr>
 <?
 }
 ?>
</table>
<?
mysql_close($con);
?>
